package org.example.design.decorator.example1;

/**
 * @author huangshen
 * @version 0
 * @description FullBorder
 * @since 2022/2/9 0:02
 */
public class FullBorder extends Border {

    public FullBorder(Display display) {
        super(display);
    }

    /**
     * 获取横向字符数
     *
     * @return
     */
    @Override
    public int getColumns() {
        return 1 + display.getColumns() + 1;
    }

    /**
     * 获取纵向行数
     *
     * @return
     */
    @Override
    public int getRows() {
        return 1 + display.getRows() + 1;
    }

    /**
     * 获取第row行的字符串
     *
     * @param row
     * @return
     */
    @Override
    public String getRowText(int row) {
        if (row == 0 ) {
            return  "+" + makeLine('-' , display.getColumns()) + "+";
        } else if(row == display.getRows() + 1 ) {
            return  "+" + makeLine('-' , display.getColumns()) + "+";
        } else {
            return  "|" + display.getRowText(row - 1) + "|";
        }
    }

    private String makeLine (char ch, int count) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < count; i++) {
            builder.append(ch);
        }
        return builder.toString();
    }
}
